﻿// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
//
// SettingsFlyout.xaml.cpp
// Implementation of the SettingsFlyout class
//

#include "pch.h"
#include "LonLatController.h"
#include "MessageDialog.h"
#include "SettingsFlyout.xaml.h"
#include "UserSettings.h"

using namespace Weathr;

using namespace Platform;
using namespace Windows::Foundation;
using namespace Windows::Foundation::Collections;
using namespace Windows::UI::ApplicationSettings;
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Controls;
using namespace Windows::UI::Xaml::Controls::Primitives;
using namespace Windows::UI::Xaml::Data;
using namespace Windows::UI::Xaml::Input;
using namespace Windows::UI::Xaml::Media;
using namespace Windows::UI::Xaml::Navigation;
using namespace Windows::UI::Popups;

// The Settings Flyout item template is documented at http://go.microsoft.com/fwlink/?LinkId=273769

Weathr::SettingsFlyout::SettingsFlyout()
{
    InitializeComponent();

    DataContext = UserSettings::Current;
}

// <summary>
// This event is generated when the user opens the settings pane. During this event, append your 
// SettingsCommand objects to the available ApplicationCommands vector to make them available to the 
// SettingsPange UI. 
// </summary>
//
// <param name="sender">Instance that triggered the event.</param>
// <param name="e">Event data describing the conditions that led to the event.</param>
void Weathr::SettingsFlyout::RegisterAppSettingsPane(SettingsPane^ sender, SettingsPaneCommandsRequestedEventArgs^ e)
{
    auto command = ref new SettingsCommand("SettingsContractID", "Options",
        ref new UICommandInvokedHandler([](IUICommand^ handler) {
            auto mySettings = ref new Weathr::SettingsFlyout();
            mySettings->Show();
    })
        );

    e->Request->ApplicationCommands->Append(command);
}

void Weathr::SettingsFlyout::SettingsFlyout_Loaded(Object^ sender, RoutedEventArgs^ e)
{
    // Prevent flyout input from manipulating the scene.
    LonLatController::Current->SuspendInput();
}

void Weathr::SettingsFlyout::SettingsFlyout_Unloaded(Object^ sender, RoutedEventArgs^ e)
{
    // Enable user input.
    LonLatController::Current->ResumeInput();
}
